home *** CD-ROM | disk | FTP | other *** search
- head 5.2;
- branch 5.2.0;
- access;
- symbols
- RELEASE:5.2.0.4
- BETA:5.2.0.3
- UICSO:5.2.0
- VANILLA:5.2;
- locks; strict;
- comment @ * @;
-
-
- 5.2
- date 91.05.17.18.43.10; author paul; state Exp;
- branches
- 5.2.0.1;
- next ;
-
- 5.2.0.1
- date 91.05.18.18.21.48; author paul; state Exp;
- branches;
- next 5.2.0.2;
-
- 5.2.0.2
- date 91.05.18.23.04.30; author paul; state Exp;
- branches;
- next 5.2.0.3;
-
- 5.2.0.3
- date 91.05.23.21.42.15; author paul; state Exp;
- branches;
- next 5.2.0.4;
-
- 5.2.0.4
- date 91.06.24.20.19.37; author paul; state Exp;
- branches;
- next ;
-
-
- desc
- @Set/Unset variables in the environment.
- @
-
-
- 5.2
- log
- @5.65 distribution
- @
- text
- @/*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
- #if defined(LIBC_SCCS) && !defined(lint)
- static char sccsid[] = "@@(#)setenv.c 5.2 (Berkeley) 6/27/88";
- #endif /* LIBC_SCCS and not lint */
-
- char *malloc(), *realloc(), *_findenv();
-
- /*
- * setenv --
- * Set the value of the environmental variable "name" to be
- * "value". If rewrite is set, replace any current value.
- */
- setenv(name, value, rewrite)
- register char *name, *value;
- int rewrite;
- {
- extern char **environ;
- static int alloced; /* if allocated space before */
- register char *C;
- int l_value, offset;
-
- if (*value == '=') /* no `=' in value */
- ++value;
- l_value = strlen(value);
- if ((C = _findenv(name, &offset))) { /* find if already exists */
- if (!rewrite)
- return(0);
- if (strlen(C) >= l_value) { /* old larger; copy over */
- while (*C++ = *value++);
- return(0);
- }
- }
- else { /* create new slot */
- register int cnt;
- register char **P;
-
- for (P = environ, cnt = 0; *P; ++P, ++cnt);
- if (alloced) { /* just increase size */
- environ = (char **)realloc((char *)environ,
- (u_int)(sizeof(char *) * (cnt + 2)));
- if (!environ)
- return(-1);
- }
- else { /* get new space */
- alloced = 1; /* copy old entries into it */
- P = (char **)malloc((u_int)(sizeof(char *) *
- (cnt + 2)));
- if (!P)
- return(-1);
- bcopy(environ, P, cnt * sizeof(char *));
- environ = P;
- }
- environ[cnt + 1] = NULL;
- offset = cnt;
- }
- for (C = name; *C && *C != '='; ++C); /* no `=' in name */
- if (!(environ[offset] = /* name + `=' + value */
- malloc((u_int)((int)(C - name) + l_value + 2))))
- return(-1);
- for (C = environ[offset]; (*C = *name++) && *C != '='; ++C);
- for (*C++ = '='; *C++ = *value++;);
- return(0);
- }
-
- /*
- * unsetenv(name) --
- * Delete environmental variable "name".
- */
- void
- unsetenv(name)
- char *name;
- {
- extern char **environ;
- register char **P;
- int offset;
-
- while (_findenv(name, &offset)) /* if set multiple times */
- for (P = &environ[offset];; ++P)
- if (!(*P = *(P + 1)))
- break;
- }
- @
-
-
- 5.2.0.1
- log
- @Added contents of getenv.c appropriately #ifdef'ed
- @
- text
- @d18 3
- a20 4
- #if !defined(lint)
- static char sccsid[] = "@@(#)setenv.c 5.2 (Berkeley) 6/27/88, %I% local";
- static char rcsid[] = "@@(#)$Id$";
- #endif /* not lint */
- d22 1
- a22 1
- #include "sendmail.h"
- a23 1
- #if defined(NEED_GETENV) || defined(NEED_SETENV) || defined(NEED_UNSETENV)
- a24 28
- * _findenv --
- * Returns pointer to value associated with name, if any, else NULL.
- * Sets offset to be the offset of the name/value combination in the
- * environmental array, for use by setenv(3) and unsetenv(3).
- * Explicitly removes '=' in argument name.
- */
- static char *
- _findenv(name, offset)
- register char *name;
- int *offset;
- {
- extern char **environ;
- register int len;
- register char **P, *C;
-
- for (C = name, len = 0; *C && *C != '='; ++C, ++len);
- for (P = environ; *P; ++P)
- if (!strncmp(*P, name, len))
- if (*(C = *P + len) == '=') {
- *offset = P - environ;
- return(++C);
- }
- return(NULL);
- }
- #endif /* NEED_GETENV || NEED_SETENV || NEED_UNSETENV */
-
- #ifdef NEED_SETENV
- /*
- a79 1
- #endif /* NEED_SETENV */
- a80 1
- #ifdef NEED_UNSETENV
- a97 16
- #endif /* NEED_UNSETENV */
-
- #ifdef NEED_GETENV
- /*
- * getenv --
- * Returns ptr to value associated with name, if any, else NULL.
- */
- char *
- getenv(name)
- char *name;
- {
- int offset;
-
- return(_findenv(name, &offset));
- }
- #endif /* NEED_GETENV */
- @
-
-
- 5.2.0.2
- log
- @Re-ordered #include "sendmail.h" .
- @
- text
- @a17 2
- #include "sendmail.h"
-
- d20 1
- a20 1
- static char rcsid[] = "@@(#)$Id: setenv.c,v 5.2.0.1 1991/05/18 18:21:48 paul Exp paul $";
- d22 2
- @
-
-
- 5.2.0.3
- log
- @Further changes for Interactive Systems UNIX adapted from patches
- sent by Andy Linton <Andy.Linton@@comp.vuw.ac.nz>.
- @
- text
- @d22 1
- a22 1
- static char rcsid[] = "@@(#)$Id: setenv.c,v 5.2.0.2 1991/05/18 23:04:30 paul Exp paul $";
- a23 4
-
- #if defined(ISC)
- # include <sys/bsdtypes.h>
- #endif /* ISC */
- @
-
-
- 5.2.0.4
- log
- @Relocated sccsid/rcsid inside NEED_* wrapper.
- @
- text
- @d20 5
- a29 6
-
- # if !defined(lint)
- static char sccsid[] = "@@(#)setenv.c 5.2 (Berkeley) 6/27/88";
- static char rcsid[] = "@@(#)$Id: setenv.c,v 5.2.0.3 1991/05/23 21:42:15 paul Exp $";
- # endif /* not lint */
-
- @
-